
<notempty name="car_info">
    <table class="layui-table">
        <volist name="car_fields" id="car_field" key="k">
            <tr>
                <td>{$car_field}</td>
                <if condition="in_array($key,$img)">
                        <php>$thumb = $key.'_thumb';</php>
                        <td class="layer-photos-demo">
                            <img id="image_{$k}" layer-src="{$car_info[$key]}" alt="{$car_info['driver_name']}{$field}" src="{$car_info[$thumb]?:$car_info[$key]}">
                            <button type="button" class="layui-btn uploads2"  id="upload-{$k}-{$key}" >上传图片</button>
                        </td>
                    <else/>
                    <td>
                        <if condition="in_array($key,$Think.config.ADMIN_EDIT.xm_car_info)">
                         <input type="text" value="{$car_info[$key]}" class="layui-input abc" style="width:150px;display: inline;margin-right: 15px"><button class="layui-btn layui-btn-danger layui-btn-sm" onclick="admin_update(this,'xm_car_info','{$key}','car_id',{$car_info['car_id']})">修 改</button> 
                        <else />
                         {$car_info[$key]}
                        </if>
                    </td>
                </if>
            </tr>
        </volist>
    </table>
    <script>

        layui.use(['layer','upload'], function(){  
            var layer = layui.layer;
            var upload = layui.upload;
               layer.photos({
                photos: '.layer-photos-demo'
                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                ,tab: function(pic, layero){
                    var str = "<div style='text-align: center'>"+pic.alt+"</div>";
                    layero.prepend(str);
                }
            });
                
            var k;
            var table_field;
            var table_id = {$car_info['car_id']};
            upload.render({
                elem: '.uploads2'//这个就等同于点击
                ,url: '/admin/Upload/upload'
                ,before: function(obj){
                    var id_str='';
                    id_str=this.item.context.id
                    var arr=id_str.split("-");
                    k = arr[1];
                  
                    table_field =  arr[2];
                    console.log(table_field)
                  //预读本地文件示例，不支持ie8
                }
                ,done:  function(res){ //上传后的回调
                  
                  if(res.status == 1){
                    $("#image_"+k).attr('src',res.data.file); //点击后的大图             
                    $("#image_"+k).attr('layer-src',res.data.file_thumb); //小图
                    $.post('/admin/upload/image_edit',{'table_name':'xm_car_info','table_field':table_field,'table_id':'car_id','id_value':table_id,'field_value':res.data.file,'thumb':res.data.file_thumb},function(data){
                        console.log(data)
                        if(data.code == 1){
                            layer.msg(data.msg,{icon: 1}); 
                        }else{
                            layer.msg(data.msg,{icon: 2}); 
                        }
                    },'json')               
                  }else{
                    layer.msg(res.msg);
                  }
                  
                }
                ,error: function(e){
                    console.log(e)
                  //layer.msg('上传失败');
                 
                }
                });  
        
            

   });
    </script>
    <else/>
    <div style="margin: 0 auto">没有相关信息</div>
</notempty>


